package xyz.xtt.admin.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import xyz.xtt.admin.entity.TblUser;
import xyz.xtt.admin.service.IUserService;
import xyz.xtt.admin.utils.PageUtilV2;
import xyz.xtt.admin.vo.UserVo;
import xyz.xtt.common.response.ApiResult;

import java.util.Optional;

/**
 * <p>
 * 用户基础信息表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/api/admin/user")
public class UserController {

    @Autowired
    private IUserService userService;
    @Autowired
    private PageUtilV2 pageUtil;

    @GetMapping("/list")
    public ApiResult<Page<UserVo>> getList(Integer current, Integer pageSize, String phone, String id, String nickname) throws Exception {
        Long Id = Optional.ofNullable(id).filter(StringUtils::isNotBlank).map(Long::parseLong).orElse(null);
        current = pageUtil.getCurrent(current);
        pageSize = pageUtil.getPageSize(pageSize);
        return ApiResult.ok(userService.getList(current, pageSize,phone, Id, nickname));
    }
}
